# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgname=apache-tika
_srvname=tika-server
_appname=tika-app
pkgver=2.9.2
pkgrel=1
pkgdesc='Toolkit for detecting and extracting metadata and structured text content.'
arch=('any')
license=('Apache')
url='https://tika.apache.org/download.html'
depends=('java-environment' 'bash')
source=("https://www.apache.org/dyn/closer.lua/tika/$pkgver/$_srvname-$pkgver.jar"
        "https://www.apache.org/dyn/closer.lua/tika/$pkgver/$_appname-$pkgver.jar"
        "$pkgname.service")
noextract=("$_srvname-$pkgver.jar" "$_appname-$pkgver.jar")
sha512sums=('2247bb458387d14f39c8f0782f61193eeba052a1e0f8f16649ecca5b25d3d9d47452a2079272e9e74f76ce6138b08c019ec156f89ec3781aa39f2c5e99b397af'
            '0f805762e0b4a5b59f7a623480f27d3db43117f03a509e20c0b78fc1d37e385ca27a329e29629d4f93cbde5f1ab2491a3db514e40d096565aadd5f5d70cf678c'
            '7eb7ce2a2ed76ad197e247689484cf1e241f26b8cbe41e4663f42d98a22f6df5505a3df9e491e70ee3d059db4ea960ab58ca12c5593f69f97a575e46dcc2fcbf')

package() {
  install -dm 755 "$pkgdir/usr/bin"

  install -Dm 755 -t "$pkgdir/usr/share/java/$pkgname/" \
    "$_srvname-$pkgver.jar" "$_appname-$pkgver.jar"
  install -Dm 644 "$pkgname.service" \
    "$pkgdir/usr/lib/systemd/system/$pkgname.service"

  cat > "$pkgdir/usr/bin/tika-server" << EOF
#!/bin/sh
"$JAVA_HOME/bin/java" -jar \
  "/usr/share/java/$pkgname/$_srvname-$pkgver.jar" "\$@"
EOF

  chmod +x "$pkgdir/usr/bin/tika-server"

  cat > "$pkgdir/usr/bin/tika-app" << EOF
#!/bin/sh
"$JAVA_HOME/bin/java" -jar \
  "/usr/share/java/$pkgname/$_appname-$pkgver.jar" "\$@"
EOF

  chmod +x "$pkgdir/usr/bin/tika-app"
}

